# -*- coding:UTF-8 -*-
import smtplib
from email.mime.text import MIMEText

#配置信息
mail_server         ='smtp.163.com'  #qq:'smtp.qq.com
mail_user_name      ='hu'
mail_user_passwd    ='****'
mail_postfix        ='163.com'
mail_to_list        =['hu_xiao_liang@163.com','renzhewudihu@163.com','huxl@knowbox.cn']

info_list = [mail_server,mail_user_name,mail_user_passwd ,mail_postfix]

'''
to_list:    目的邮件地址
sub:        邮件的主题
content:    邮件的内容
'''
def send_mail(list,to_list,sub,content):
    #设置服务器，用户名、口令以及邮箱的后缀
    from_email=mail_user_name+'@'+mail_postfix
    msg = MIMEText(content,_subtype='text/plain',_charset='utf-8')
    msg['Subject'] = sub
    msg['From'] = from_email
    msg['To'] = ','.join(to_list)
    try:
        s = smtplib.SMTP()
        s.connect(mail_server)
        s.login(mail_user_name,mail_user_passwd)
        s.sendmail(msg['From'], msg['To'], msg.as_string())
        s.close()
        return True
    except Exception, e:
        print 'mail error:'
        print str(e)
        return False

if __name__ == '__main__':
    if send_mail(info_list,mail_to_list,'周报','下午好'):
        print 'send success'
    else:
        print 'send failed'
